<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('文件归档') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('文件名称')" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          :placeholder="$t('文件名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('用印一级')" prop="sealTypeOne">
        <el-select v-model="queryParams.sealTypeOne" :placeholder="$t('用印一级')" clearable>
          <el-option
            v-for="dict in sealTypeOneOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('用印二级')" prop="sealTypeTwo">
        <el-select v-model="queryParams.sealTypeTwo" :placeholder="$t('用印二级')" clearable>
          <el-option
            v-for="dict in sealTypeTwoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('存放地')" prop="storagePlace">
        <el-input
          v-model="queryParams.storagePlace"
          :placeholder="$t('存放地')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('保管人')" prop="custodian">
        <UserSelect v-model="queryParams.custodian" :placeholder="$t('保管人')" />
      </el-form-item>
      <el-form-item :label="$t('是否完成归档')" prop="archiveCompleted">
        <el-select
          v-model="queryParams.archiveCompleted"
          :placeholder="$t('请选择')"
          clearable
          @keyup.enter.native="queryHandle"
        >
          <el-option value="是">{{ $t('是') }}</el-option>
          <el-option value="否">{{ $t('否') }}</el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" />

    <el-table v-loading="loading" :data="oaFilingList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('关联用印')" align="center" prop="sealName" min-width="150">
        <template slot-scope="scope">
          <el-link type="primary" @click="findHandle(scope.row)">
            <span> {{ scope.row.sealName }}</span>
          </el-link>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('用印类型一级')"
        align="center"
        prop="sealTypeOne"
        :formatter="sealTypeOneFormat"
        min-width="130"
      />
      <el-table-column
        :label="$t('用印类型二级')"
        align="center"
        prop="sealTypeTwo"
        :formatter="sealTypeTwoFormat"
        min-width="130"
      />
      <el-table-column :label="$t('归档人')" align="center" prop="archivingPersonnelName" min-width="130" />
      <el-table-column :label="$t('存放地')" align="center" prop="storagePlace" min-width="130" />
      <el-table-column :label="$t('保管人')" align="center" prop="custodianName" min-width="130" />
      <el-table-column :label="$t('创建时间')" align="center" prop="applyTime" width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('预计归档时间')" align="center" prop="estimatedArchivingTime" width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estimatedArchivingTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('文件类型')" align="center" prop="fileType" min-width="130" />
      <el-table-column :label="$t('文件名称')" align="center" prop="fileName" min-width="130">
        <template slot-scope="scope">
          <thumbnail :file-data="scope.row" :file-id="scope.row.fileId" />
          <el-input v-show="false" v-model="scope.row.fileName" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('归档编号')" align="center" prop="filingNo" min-width="130" />
      <el-table-column :label="$t('是否归档')" align="center" prop="archiveOrNot" min-width="130" />
      <el-table-column :label="$t('归档日期')" align="center" prop="filingDate" min-width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.filingDate) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :title="$t(title)"
      :visible.sync="formOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm"
      append-to-body
    >
      <oa-seal-form ref="oaSealForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listOaFilingPool } from '@/api/oa/filing/oaFiling'
import OaSealForm from '@/views/oa/seal/oaSealForm'

export default {
  components: { OaSealForm },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 文件归档表格数据
      oaFilingList: [],
      // 弹出层标题
      title: '文件归档',
      formOpen: false,
      // 用印类型一级字典
      sealTypeOneOptions: [],
      // 用印类型二级字典
      sealTypeTwoOptions: [],
      // 查询参数
      queryParams: {
        sealId: undefined,
        archivingPersonnel: undefined,
        sealTypeOne: undefined,
        sealTypeTwo: undefined,
        storagePlace: undefined,
        custodian: undefined,
        applyTime: undefined,
        estimatedArchivingTime: undefined,
        archiveCompleted: undefined,
        actStatus: undefined,
        fileName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('seal_usine_type').then(response => {
      this.sealTypeOneOptions = response.data
    })
    this.getDicts('seal_usine_type_two_all').then(response => {
      this.sealTypeTwoOptions = response.data
    })
  },
  methods: {
    /** 查询文件归档列表 */
    getList() {
      this.loading = true
      listOaFilingPool(this.queryParams).then(response => {
        this.oaFilingList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 用印类型一级字典翻译
    sealTypeOneFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.sealTypeOneOptions, row.sealTypeOne)
    },
    // 用印类型二级字典翻译
    sealTypeTwoFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.sealTypeTwoOptions, row.sealTypeTwo)
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        sealId: undefined,
        sealName: undefined,
        archivingPersonnel: undefined,
        sealTypeOne: undefined,
        sealTypeTwo: undefined,
        storagePlace: undefined,
        custodian: undefined,
        applyTime: undefined,
        estimatedArchivingTime: undefined,
        archiveCompleted: undefined,
        remark: undefined,
        actId: undefined,
        actStatus: '0',
        actTitle: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams.archiveCompleted = undefined
      this.queryParams.storagePlace = undefined
      this.queryParams.custodian = undefined
      this.queryParams.sealTypeTwo = undefined
      this.queryParams.sealTypeOne = undefined
      this.queryHandle()
    },
    // 关联用印
    findHandle(row) {
      this.formOpen = true
      row.id = row.sealId
      this.$nextTick(() => {
        this.$refs.oaSealForm.init(row)
      })
    }

  }
}
</script>
